package lib.bone.nepudata.domain.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lib.bone.common.converter.JpaListLongConverter;
import lombok.*;
import org.hibernate.Hibernate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @Author : kindear
 * @Date : 2021-12-14
 */
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@Table(name = "nepu_book")
@EntityListeners(AuditingEntityListener.class)
@ApiModel(value = "著作教材成果")
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")
public class NepuBook {
    @Id
    @GeneratedValue(generator = "jpa-uuid")
    @ApiModelProperty(value = "著作/教材ID",name =  "id")
    String id;

    @ApiModelProperty("周期ID")
    @Column(name = "cycle_id")
    String cycleId;

    /**
     * 著作词典ID
     */
    @ApiModelProperty(value = "著作词典ID",notes = "")
    @Column(name = "book_dict_id")
    String bookDictId;

    @ApiModelProperty(value = "著作教材名称",notes = "")
    @Column(name = "book_name")
    String bookName;

    /**
     * 字数 单位（万字）
     */
    @ApiModelProperty(value = "字数",notes = "单位（万字）")
    @Column(name = "words_number",scale = 2)
    Double wordsNumber;

    /**
     * 出版时间
     */
    @ApiModelProperty(value = "出版时间")
    @Column(name = "publication_date")
    Date publicationDate;

    /**
     * 署名单位
     */
    @ApiModelProperty(value = "署名单位")
    @Column(name = "signature_unit")
    String signatureUnit;

    /**
     * 第一作者姓名
     */
    @ApiModelProperty(value = "第一作者",notes = "")
    @Column(name = "first_author")
    String firstAuthor;

    /**
     * 第一作者ID
     */
    @ApiModelProperty(value = "第一作者ID",notes = "")
    @Column(name = "first_author_id")
    Long firstAuthorId;

    /**
     * 参与人员ID
     */
    @ApiModelProperty(value = "著书成员ID列表",notes = "")
    @Convert(converter = JpaListLongConverter.class)
    @Column(name = "user_id_list")
    List<Long> userIdList;

    /**
     * 出版社
     */
    @ApiModelProperty(value = "出版社",notes = "")
    @Column(name = "publisher")
    String publisher;

    @ApiModelProperty(value = "工作量",notes = "")
    @Column(name = "workload",scale = 2)
    Double workload;

    /**
     * 审核状态
     */
//    @ApiModelProperty("审核状态")
//    @Column(name = "status")
//    Integer status;

    @CreatedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录创建时间",name = "createdTime")
    @Column(name = "created_time")
    private Date createdTime;

    @LastModifiedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录更新时间",name = "updatedTime")
    @Column(name = "updated_time")
    private Date updatedTime;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
        NepuBook nepuBook = (NepuBook) o;
        return id != null && Objects.equals(id, nepuBook.id);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}
